<?  include('../includes/loader.inc.php'); 

	$config = array (
		'title' 	=> 'Peliculas',
		'module' 	=> 'peliculas',
		'class'		=> 'Peliculas',
		'key'		=> 'id_pelicula',
	);

	// Instancio la clase
	$obj = new $config['class']();

	if ($_POST['data']) {
	
		foreach ($_POST['data'] as $clase => $campos) {

			// Instancio el objeto si no estaba instanciado
			if (!${$clase})
				${$clase} = new $clase();

			// Guardo los nuevos datos
			${$clase}->save($campos);
		}
		
		// Redirecciono
		header("Location: ".(($url = $Session->get($config['module'].'_listado'))? $url : '/admin/'.$config['module'].'/'));
		exit;
	}

	// Obtengo el producto a modificar
	$pelicula = $obj->get($_GET['id']);
	$row = $pelicula['pelicula'];
	$row['imagenes'] = $pelicula['imagenes'];

	// Obtengo los tipos
	$Tipos = new Tipos();
	$tipos = $Tipos->listar();

//echo '<pre>'.print_r($row, true).'</pre>';

?>
<!DOCTYPE html>

<html>

<head>
	
	<title><?=$config['title']?></title>

	<?	include('modules/head.inc.php'); ?>
	
</head>

<body class="<?=$admin['config']['theme']?>">

	<!--<div class="login-back"></div>

	<div class="titlebar"></div>
	
	<div class="window">
	
		<div class="content">-->

			<?  include('modules/header.inc.php'); ?>

			<div class="space clear"></div>

			<div class="container" data-object="">
			
				<h2><?=($config['title'])?></h2>
				
				<div class="space clear"></div>
			
				<!-- Content -->

				<form method="post" enctype="multipart/form-data" id="main-form" action="<?=$PHP_SELF?>" class="edit">
					<!-- hidden -->
					<input type="hidden" name="data[<?=$config['class']?>][primary_key]" value="<?=$config['key']?>">
					<input type="hidden" name="data[<?=$config['class']?>][<?=$config['key']?>]" value="<?=$_GET['id']?>">
					
					<div class="legend"><h3><?=$config['title']?></h3></div>
						
					<?#	foreach ($data['update'] as $id => $update): ?>
					
						<?=($id > 0)? '<div class="itemid">'.$id.'</div>' : ''?>
						
						<ul class="list">
					
							<!-- text -->
							<li>
								<p><label for="form-titulo">Titulo</label></p>
								<p><input type="text" class="large" id="form-titulo" name="data[<?=$config['class']?>][titulo]" value="<?=$row['titulo']?>"/></p>
							</li>

							<li>
								<p><label for="form-imagen-principal">Imagen Principal</label></p>
								<p>
									<input type="file" id="form-imagen-principal" name="data[<?=$config['class']?>][img]" value=""/>
									<?=($row['img'])? '<a href="'.CONFIG_SITE_URL.$obj->path.$row['img'].'" target="_blank">[Ver imagen actual]</a> <!--<a href="">[borrar imagen actual]</a>-->' : ''?>
								</p>
							</li>

							<li>
								<p><label for="form-video">Video</label></p>
								<p>
									<!--<span id="file-uploader"></span>-->
									<input type="text" class="large" id="form-video" name="data[<?=$config['class']?>][video]" value="<?=end(explode('/', $row['video']))?>"/>
									<?=($row['video'] && is_file(CONFIG_DOCUMENT_ROOT.$row['video']))? '<a href="'.CONFIG_SITE_URL.$row['video'].'" style="display:block;width:640px;height:360px;" id="player"></a>' : ''?>
								</p>
							</li>

							<li>
								<p><label for="form-link">Link <br />(para invitacion interactiva)</label></p>
								<p><input type="text" class="large" id="form-link" name="data[<?=$config['class']?>][link]" value="<?=$row['link']?>"/></p>
							</li>

							<!-- select -->
							<li>
								<p ><label for="form-tipo">Tipo</label></p>
								<p>
									<select id="form-tipo" name="data[<?=$config['class']?>][id_pelicula_tipo]">
										<option value="0">Sin Tipo</option>
										<? foreach($tipos as $key => $val): ?>
											<option value="<?=$key?>" <?=($key == $row['id_pelicula_tipo'])? 'selected="selected"' : '' ?> ><?=ucfirst($val['nombre'])?></option>
										<? endforeach; ?>
									</select>
								</p>
							</li>

							<li>
								<p ><label for="form-recomendado">Recomendado (home)</label></p>
								<p>
									<input id="form-recomendado" value="1" type="checkbox" name="data[<?=$config['class']?>][recomendado]" <?=(isset($row['recomendado']) && ($row['recomendado']==1))? 'checked="checked"' : ''?> >
								</p>
							</li>

							<li>
								<p><label for="form-descripcion">Descripcion</label></p>
								<p><textarea style="width: 600px; height: 150px;" id="form-descripcion" name="data[<?=$config['class']?>][descripcion]"><?=$row['descripcion']?></textarea></p>
							</li>

						</ul>

					<?#	endforeach; ?>
						
					<div class="submits">
					
						<button type="submit" name="action" value="Guardar" class="capitalize button">Guardar</button>
						
					</div>

				</form>


				<!-- /Content -->

				
			</div>

			<?	include('modules/footer.inc.php'); ?>
		
		<!--</div>
		
	</div>-->
			
<!-- File uploader -->
<script src="/admin/js/plugins/upload/fileuploader.js"></script>
<link rel="stylesheet" href="/admin/js/plugins/upload/fileuploader.css" type="text/css"/>

<script src="/js/plugins/flowplayer/flowplayer-3.2.10.min.js"></script>


	<script src="/admin/js/universal.js"></script>

</body>	
	
</html>

